<?php
// +----------------------------------------------------------------------
// | DCloud [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.yunku.cloud All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace plugins\un_transport_order;

use dc\lib\Plugin;
use dragon\SysConfig;
use think\Db;

class UnTransportOrderPlugin extends Plugin
{

    public $info = [
        'name'        => 'UnTransportOrder',
        'title'       => '待运输',
        'description' => '待运输',
        'status'      => 1,
        'author'      => 'Dr.Dragon',
        'version'     => '1.0'
    ];

    public $hasAdmin = 0;//插件是否有后台管理界面

    // 插件安装
    public function install()
    {
        return true;//安装成功返回true，失败false
    }

    // 插件卸载
    public function uninstall()
    {
        return true;//卸载成功返回true，失败false
    }

    public function adminDashboard()
    {
        $user = config('user_info');
        $company = config('company_info');
        $map = [];
        // 权限
        $map['status'] = ['in', SysConfig::$unTransportOrderStatus];
        if($user->isDispatcher()) {
            $map['transport_mode'] = SysConfig::TRANSPORT_PLATFORM;
        } elseif ($user->isCompanyUser()) {
            $map['company_id'] = $company->id;
        }

        $emptyList = Db::name('order')->where($map + ['order_type' => SysConfig::EMPTY_CONTAINER_GATE_OUT])->paginate(6);
        $loadedList = Db::name('order')->where($map + ['order_type' => SysConfig::LOADED_CONTAINER_GATE_IN])->paginate(6);
        $gateInList = Db::name('order')->where($map + ['order_type' => SysConfig::CONTAINER_GATE_IN])->paginate(6);
        $gateOutList = Db::name('order')->where($map + ['order_type' => SysConfig::CONTAINER_GATE_OUT])->paginate(6);

        $this->assign('user', $user);
        $this->assign('empty_list', $emptyList);
        $this->assign('empty_total', $emptyList->total());
        $this->assign('loaded_list', $loadedList);
        $this->assign('loaded_total', $loadedList->total());
        $this->assign('gate_in_total', $gateInList->total());
        $this->assign('gate_out_total', $gateOutList->total());

        return [
            'width'  => 6,
            'view'   => $this->fetch('widget'),
            'plugin' => 'UnTransportOrder'
        ];
    }

}